//
//  UIBarButtonItem+PPBarButtonItem.m
//  pickpic
//
//  Created by 胡文广 on 2017/5/1.
//  Copyright © 2017年 MicroDream. All rights reserved.
//

#import "UIBarButtonItem+PPBarButtonItem.h"

@implementation UIBarButtonItem (PPBarButtonItem)
+ (instancetype)barButtonItemWithImageName:(NSString *)imageName itemColor:(UIColor *)itemColor target:(id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    if (itemColor) {
//        btn.tintColor = itemColor;
//    }
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn sizeToFit];
    return [[self alloc] initWithCustomView:btn];
    
}

+ (instancetype)barButtonItemImageIcon:(NSString*)ImageIcon target:(id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:ImageIcon] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn sizeToFit];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 44)];
    btn.bounds = view.bounds;
    btn.center = view.center;
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [view addSubview:btn];
    
    return [[self alloc] initWithCustomView:view];
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
   
    if (IS_IOS_8) {
        btn.titleLabel.font = PFFontBold(16);
    }else{
        
      btn.titleLabel.font = PPFONT(PFBold, 16);
    }
    
    
    btn.titleEdgeInsets = UIEdgeInsetsMake(3, 0, 0, 0);
    [btn setTitleColor:BLACK forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn sizeToFit];
    return [[self alloc] initWithCustomView:btn];
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title image:(NSString *)image target:(id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = PPFONT(PFMedium, 16);
    
    
    if (IS_IPHONE_6_PLUS) {
        
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, -3, 0, 0);
    }
    
    btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -5);
    
    [btn setTitleColor:BLACK forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn sizeToFit];
    return [[self alloc] initWithCustomView:btn];
    
}

+ (instancetype)barButtonItemImageIcon:(NSString*)ImageIcon leftMargin:(CGFloat)leftMargin target:(id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:ImageIcon] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn sizeToFit];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 44)];
    btn.bounds = view.bounds;
    btn.center = view.center;
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, -leftMargin, 0, 0);
    [view addSubview:btn];
//    view.backgroundColor =RED;
    return [[self alloc] initWithCustomView:view];
}
@end
